
/* Project Name: Bank_Note Receiver ( base Counter project)
	Author: Dima
	Date: 12.01.2007*/
/*
  PROTOCOL FORMAT:
*/


#include <pic.h>
#include "my_macros.h"
//#include "UART.h"
#include "Inputs.h" 
#include "SysTime.h" 
#include "Receiver.h" 

__CONFIG(MCLRDIS & WDTDIS & BOREN & PROTECT & PWRTEN & LVPDIS & INTCLK); // INTIO );

/* 
1. Interrupt power off
2. Stop hooper if no coins
3. 1, 5, 10 by jumpers
 */

void InitDevice ( void )
{
	CLRWDT();
	//OPTION = 0b10000111;			  /* pull-ups disable 1:128 */
	OPTION = 0b10000101;			  /* pull-ups disable + TMR0 1:64 */
	CMCON = 0x07;
	PORTA = 0;
	TRISA = 0b11111111;
	PORTB = 0;
	TRISB = 0b11111111;

/*    /\* UART *\/ */
/* //	InitUART(); */
/* 	CREN = 0; */

	T0IF = 0;
	T0IE = 1;

	PEIE = TRUE;
	GIE = 0;
}

void SaveData_Init ( void )
{
	/* Safe Mode definitions */
	INTEDG = 1;						  /* interrupt on the rise of RB0 for Safe Mode */
	INTF = 0;
	INTE = 1;
}

void main ( void )
{
	InitDevice();
	Inputs_Init();
	Receiver_Init();
	delay_ms(200);
	SaveData_Init();
	GIE = 1;

	for (;;) // Main Loop
	{
		SysTime();
		Drive_Inputs();
		Drive_Receiver();		

	} // Main Loop
}

